<template>
  <div id="app">
	  <vue-loading v-show="showload" type="bubbles" style="position:absolute;left:0;top:0;background:white;z-index:100;" color="#d9544e" :size="{ width: '100%', height: '100%' }"></vue-loading>
		<transition name="change">
    <router-view :goods="sell" ref="view"></router-view>
		</transition>
  </div>
</template>

<script>
	
import vueLoading from 'vue-loading-template'
import qs from 'qs'
export default {
  name: 'app',
  data() {
		return {
			ss:12,
			sell:[],
			showload:true
		}
	},
	mounted:function(){
			var da=new Date()
			console.log(da.getTime())
				this.getData();
		},
	methods:{
		getData1:function(){
			var _this=this
			if(!localStorage.order){
			this.$http.get('../static/order.json')
			.then(response=>{
				_this.showload=!_this.showload
					 _this.sell=response.data;
					 localStorage.order=JSON.stringify(_this.sell);
						_this.$refs.view.occur()
			})
			}
			else{
				_this.showload=!_this.showload
				 _this.sell=JSON.parse(localStorage.order)
				 _this.$refs.view.occur()
			}
		},
		getData:function(){
			var da=new Date()
			if(!localStorage.order || (da.getTime()-localStorage.time)>120000 || localStorage.sellerid!=sessionStorage.sellerid){
				
			var _this=this;
			this.$http.post(sessionStorage.baseurl+"/a/phone/getAllInFoods",qs.stringify({sellerid :sessionStorage.sellerid,token:sessionStorage.token,openid:sessionStorage.openid})).then(response => {
				if(response.data.code==1){

				_this.$http.post(sessionStorage.baseurl+"/a/phone/getFoodType",qs.stringify({sellerid :sessionStorage.sellerid,token:sessionStorage.token,openid:sessionStorage.openid})).then(res=>{
					 var allfoods=response.data.data;
					 console.log(allfoods)
					 var foodtype=res.data.data;
					 var order_foodtype=[];
					 var order_allfoods=[];
					 for (var i = 0; i < foodtype.length; i++) {
							order_foodtype.push({
								index : i,
								name : foodtype[i].name,
								num : 0,
								id : foodtype[i].id,
								list : []
							})
						}
						for (var i = 0; i < allfoods.length; i++) {
							if(allfoods[i].foodInfoList){
							for(var z=0;z<allfoods[i].foodInfoList.length;z++){
								allfoods[i].foodInfoList[z].num=0;
								allfoods[i].foodInfoList[z].foodname=allfoods[i].foodname;
							}
							order_allfoods.push({
								id : allfoods[i].id,
								typeid : allfoods[i].foodtype.id,
								listName : allfoods[i].foodname,
								num : 0,
								src : allfoods[i].foodimage1,
								orprice : allfoods[i].foodInfoList[0].price,
								price : allfoods[i].foodInfoList[0].nowprice,
								listin:allfoods[i].foodInfoList
							})
							}
						}
					 order_foodtype.forEach(function(type){
						 order_allfoods.forEach(function(food){
							if(food.typeid==type.id){
								food.listin.forEach(function(foodin){
										foodin.num=0;
										foodin.src=food.src;
										foodin.hongbaoused=0;
										foodin.doublehongbao=false;
										foodin.hongbao=[];
										foodin.jingxiused=0
								});
								type.list.push(food)
							}
						 })
					 })
					 _this.showload=!_this.showload
					 _this.sell=order_foodtype;
					 localStorage.order=JSON.stringify(_this.sell);
					 localStorage.time=da.getTime()
					 localStorage.sellerid=sessionStorage.sellerid
					 console.log(localStorage.time)
						_this.$refs.view.occur()
					
				})
				.catch(function(error){
				alert(error)
			})
				/*response.data.forEach(function(food){
					food.list.forEach(function(infood){
						infood.listin.forEach(function(foodin){
							foodin.num=0
							foodin.src=infood.src
						})
					})
				})
					_this.sell=response.data;
					_this.$nextTick(function(){
						_this.$refs.view.occur()
					})*/
				}
				else{
					alert("获取菜品数据出错")
				}
			})
			.catch(function(error){
				alert(error)
			})
		}
		else{
		 this.sell=JSON.parse(localStorage.order);
		 this.$store.commit("getAllgoods",this.sell)
		 this.showload=!this.showload
					this.$nextTick(function(){
						this.$refs.view.occur()
					})
	 }
	}
	
	},
	components:{
		vueLoading
	}
}
</script>

<style  lang="stylus" rel="stylesheet/stylus">
	 @import 'common/stylus/index'
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
	width:100%;
	height:100%;
}
.change-leave-to,.change-enter{
	opacity 0
	transform scale(0.6)
}
.change-enter-active,.change-leave-active{
	transition 0.5s
}
</style>
